package com.ja.openchat.ui.chat.group;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import androidx.lifecycle.ViewModelProviders;

import com.google.gson.JsonObject;
import com.ja.openchat.AppViewModelFactory;
import com.ja.openchat.BR;
import com.ja.openchat.R;
import com.ja.openchat.databinding.ActivityModifyFieldBinding;
import com.ja.openchat.viewmodels.ModifyFiledViewModel;
import com.zy.openchat.Constants;
import com.zy.openchat.core.manager.TelegramManager;
import com.zy.openchat.core.manager.TgResponse;
import com.zy.openchat.core.manager.TgResultBlock;
import com.zy.openchat.core.model.message.MessageInfo;
import com.zy.openchat.core.model.user.UserInfo;
import com.zy.openchat.util.KeyboardHelper;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import me.goldze.mvvmhabit.base.BaseActivity;

public class ModifyFieldActivity extends BaseActivity<ActivityModifyFieldBinding, ModifyFiledViewModel> {
    Unbinder unbinder;
    private boolean canEdite;

    private enum ModifyFieldType {
        //设置我的昵称
        ModifyFieldType_Set_My_Nickname,
        //设置我的用户名
        ModifyFieldType_Set_My_Username,
        //设置群组名称
        ModifyFieldType_Set_Group_Name,
        //设置用户备注
        ModifyFieldType_Set_User_NickName,
        //设置群组公告
        ModifyFieldType_Set_GroupNotice,
        //设置群简介
        ModifyFieldType_Set_GroupSummary,
        //设置敏感词
        ModifyFieldType_Set_Sensitive_Word,
        //设置我的签名
        ModifyFieldType_Set_My_Signature,
        //设置我的签名
        ModifyFieldType_Set_My_Group_Nick_Name
    }

    //修改类型
    private ModifyFieldType fieldType;
    //会话id
    private long chatId;
    //旧值
    private String prevValueString;
    //相关用户
    private UserInfo toBeModifyUser;

    //设置我的昵称
    public static void start_setMyNickname(Activity activity) {
        start(activity, ModifyFieldType.ModifyFieldType_Set_My_Nickname, 0, null, null);
    }

    public static void start_setMySignature(Activity activity, String prevValueString) {
        start(activity, ModifyFieldType.ModifyFieldType_Set_My_Signature, 0, prevValueString, null);
    }

    //设置我的用户名
    public static void start_setMyUsername(Activity activity) {
        start(activity, ModifyFieldType.ModifyFieldType_Set_My_Username, 0, null, null);
    }

    //设置群组名称
    public static void start_setGroupName(Activity activity, long chatId, String prevValueString) {
        start(activity, ModifyFieldType.ModifyFieldType_Set_Group_Name, chatId, prevValueString, null);
    }

    //设置在群组里的昵称
    public static void start_setGroupNickName(Activity activity, long chatId, String prevValueString) {
        start(activity, ModifyFieldType.ModifyFieldType_Set_My_Group_Nick_Name, chatId, prevValueString, null);
    }

    //设置群组公告
    public static void start_setGroupNotice(Activity activity, long chatId, String prevValueString,boolean canEdite) {
        startForResult(activity, ModifyFieldType.ModifyFieldType_Set_GroupNotice, chatId, prevValueString, null,canEdite);
    }

    //设置群简介
    public static void start_setGroupSummary(Activity activity, long chatId, String prevValueString,boolean canEdite) {
        startForResult(activity, ModifyFieldType.ModifyFieldType_Set_GroupSummary, chatId, prevValueString, null,canEdite);
    }

    //设置敏感词
    public static void start_setGroupSensitiveWord(Activity activity, long chatId, String prevValueString) {
        start(activity, ModifyFieldType.ModifyFieldType_Set_Sensitive_Word, chatId, prevValueString, null);
    }

    //设置用户备注
    public static void start_setUserRemark(Activity activity, String prevValueString, UserInfo toBeModifyUser) {
        start(activity, ModifyFieldType.ModifyFieldType_Set_User_NickName, 0, prevValueString, toBeModifyUser);
    }

    private static void start(Activity activity, ModifyFieldType type, long chatId, String prevValueString, UserInfo toBeModifyUser) {
        Intent intent = new Intent();
        intent.setClass(activity, ModifyFieldActivity.class);
        intent.putExtra("chatId", chatId);
        if (!StringUtils.isEmpty(prevValueString))
            intent.putExtra("prevValueString", prevValueString);
        if (toBeModifyUser != null)
            intent.putExtra("toBeModifyUser", toBeModifyUser);
        Bundle bundle = new Bundle();
        bundle.putSerializable("type", type);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }

    private static void startForResult(Activity activity, ModifyFieldType type, long chatId, String prevValueString, UserInfo toBeModifyUser,boolean canEdite) {
        Intent intent = new Intent();
        intent.setClass(activity, ModifyFieldActivity.class);
        intent.putExtra("chatId", chatId);
        intent.putExtra("canEdite", canEdite);
        if (!StringUtils.isEmpty(prevValueString))
            intent.putExtra("prevValueString", prevValueString);
        if (toBeModifyUser != null)
            intent.putExtra("toBeModifyUser", toBeModifyUser);
        Bundle bundle = new Bundle();
        bundle.putSerializable("type", type);
        intent.putExtras(bundle);
        activity.startActivityForResult(intent,100);
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_modify_field;
    }


    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public ModifyFiledViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用LoginViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(ModifyFiledViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();
        unbinder = ButterKnife.bind(this);
        //初始化数据
        initIntentData();
        //初始化标题
        initTitle();
        //初始化导航栏
        initToolbar();
    }

    private void initIntentData() {
        if (getIntent() != null) {
            chatId = getIntent().getLongExtra("chatId", 0);
            canEdite = getIntent().getBooleanExtra("canEdite", false);
            prevValueString = getIntent().getStringExtra("prevValueString");
            toBeModifyUser = getIntent().getParcelableExtra("toBeModifyUser");
            //类型
            Bundle bundle = getIntent().getExtras();
            fieldType = (ModifyFieldType) bundle.getSerializable("type");
            if (fieldType == null) {
                fieldType = ModifyFieldType.ModifyFieldType_Set_My_Nickname;
            }
        }
    }

    private void initTitle() {
        viewModel.setContext(this);
        binding.tvSubmit.setVisibility(View.GONE);
        binding.hintText.setVisibility(View.GONE);
        switch (fieldType) {
            case ModifyFieldType_Set_My_Nickname:
                setTitle(getString(R.string.set_nickname));
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(12)});
                binding.titleText.setText(getString(R.string.nickname_text));
                binding.valueText.setHint(getString(R.string.firstname_null_hint));
                binding.valueText.setText(UserInfo.getUserInfo().displayName());
                break;
            case ModifyFieldType_Set_My_Username:
                setTitle(getString(R.string.set_username));
                binding.hintText.setVisibility(View.VISIBLE);
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(32)});
                binding.titleText.setText(getString(R.string.username_text));
                binding.valueText.setHint(getString(R.string.edit_username_hint));
                binding.valueText.setText(UserInfo.getUserInfo().username);
                break;
            case ModifyFieldType_Set_Group_Name:
                setTitle(getString(R.string.group_name_text));
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(12)});
                binding.titleText.setText(R.string.group_name_text);
                binding.valueText.setHint(getString(R.string.input_group_name));
                binding.valueText.setText(prevValueString);
                break;
            case ModifyFieldType_Set_User_NickName:
                setTitle(getString(R.string.set_remark));
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(12)});
                binding.titleText.setText(getString(R.string.remark_text));
                binding.valueText.setHint(getString(R.string.set_remark));
                binding.valueText.setText(prevValueString);
                break;
            case ModifyFieldType_Set_GroupNotice:
                setTitle(getString(R.string.group_announcement));
                binding.titleText.setText(getString(R.string.group_announcement));
                binding.valueText.setHint(getString(R.string.fill_group_announcement));
                binding.valueText.setText(prevValueString);
                binding.valueText.setSingleLine(false);
                binding.valueText.setMinHeight(getResources().getDimensionPixelSize(R.dimen.y200));
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4000)});
//                valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(300)});
                binding.valueText.setGravity(Gravity.TOP);
                binding.tvSubmit.setText(getString(R.string.publish_group_ann_text));
                binding.tvSubmit.setVisibility(View.VISIBLE);
                break;
            case ModifyFieldType_Set_GroupSummary:
                setTitle(getString(R.string.group_introduce));
                binding.setTopLayout.setVisibility(View.GONE);
                binding.tvSubmit.setText(getString(R.string.post_group_introduction));
                binding.tvSubmit.setVisibility(View.VISIBLE);
                binding.titleText.setText(getString(R.string.group_introduce));
                binding.valueText.setHint(getString(R.string.fill_group_introduction));
                binding.valueText.setText(prevValueString);
                binding.valueText.setSingleLine(false);
                binding.valueText.setMinHeight(getResources().getDimensionPixelSize(R.dimen.y200));
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4000)});
                binding.valueText.setGravity(Gravity.TOP);
                break;
            case ModifyFieldType_Set_Sensitive_Word:
                setTitle(getString(R.string.set_sensitive_word_management));
                binding.titleText.setText(getString(R.string.sensitive_word_management));
                binding.valueText.setHint(getString(R.string.fill_sensitive_word_management));
                binding.valueText.setText(prevValueString);
                binding.valueText.setSingleLine(false);
                binding.valueText.setMinHeight(getResources().getDimensionPixelSize(R.dimen.y200));
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4000)});
//                valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(300)});
                binding.valueText.setGravity(Gravity.TOP);
                getGroupSensitive_Word();
                break;
            case ModifyFieldType_Set_My_Signature:
                setTitle(getString(R.string.set_my_signature));
                binding.titleText.setText(getString(R.string.my_signature));
                binding.valueText.setHint(getString(R.string.fill_my_signature));
                if (!TextUtils.isEmpty(prevValueString)) {
                    binding.valueText.setText(prevValueString);
                }
                binding.valueText.setSingleLine(false);
                binding.valueText.setMinHeight(getResources().getDimensionPixelSize(R.dimen.y200));
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(70)});
//                valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(300)});
                binding.valueText.setGravity(Gravity.TOP);
                break;
            case ModifyFieldType_Set_My_Group_Nick_Name:
                setTitle(getString(R.string.my_nickname_in_group));
                binding.valueText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)});
                binding.titleText.setText(getString(R.string.my_nickname_in_group));
                binding.valueText.setHint(getString(R.string.fill_my_nickname_in_group));
                binding.valueText.setText(prevValueString);
                break;
            default:
                break;
        }
        KeyboardHelper.openKeyBoard(this, binding.valueText);
    }
    public void setTitle(String title) {
        TextView titleText = findViewById(R.id.tv_bar_title);
        if (titleText != null) {
            titleText.setText(title);
        }
    }
    private void initToolbar() {
        binding.setTopLayout.setVisibility(canEdite?View.VISIBLE:View.GONE);
        switch (fieldType) {
            case ModifyFieldType_Set_My_Nickname:
            case ModifyFieldType_Set_My_Username:
            case ModifyFieldType_Set_Group_Name:
            case ModifyFieldType_Set_User_NickName:
            case ModifyFieldType_Set_Sensitive_Word:
            case ModifyFieldType_Set_My_Signature:
            case ModifyFieldType_Set_My_Group_Nick_Name:
                binding.toolbar.tvOkRight.setVisibility(View.VISIBLE);
                binding.toolbar.tvOkRight.setBackgroundResource(R.drawable.white_rectangle);
                binding.toolbar.tvOkRight.setTextColor(getResources().getColor(R.color.colorAccent));
                binding.toolbar.tvOkRight.setText(getString(R.string.save_text));
                break;
            case ModifyFieldType_Set_GroupSummary:
            case ModifyFieldType_Set_GroupNotice:
                binding.tvSubmit.setVisibility(canEdite?View.VISIBLE:View.GONE);
                binding.valueText.setFocusable(canEdite);
                binding.toolbar.tvOkRight.setVisibility(canEdite?View.VISIBLE:View.GONE);
                binding.toolbar.tvOkRight.setBackgroundResource(R.drawable.white_rectangle);
                binding.toolbar.tvOkRight.setTextColor(getResources().getColor(R.color.red8));
                binding.toolbar.tvOkRight.setText(getString(R.string.delete_text));
                break;
            default:
                break;
        }
    }

    private void saveMyNickName(String nickName) {
        if (!StringUtils.isEmpty(nickName)) {
            showProgress();
            TelegramManager.getTelegramManager().setMyNickName(this, nickName, new TgResultBlock<TgResponse>() {
                @Override
                public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                    hideProgress();
                    if (obj.ok) {//设置成功
                        finish();
                    } else {
                        showErrorTip(getString(R.string.request_error) + obj.errString);
                    }
                }

                @Override
                public void onTimeout(Map<String, Object> request) {
                    hideProgress();
                    showErrorTip(getString(R.string.request_error));
                }
            });
        } else {
            showErrorTip(getString(R.string.firstname_null_hint));
        }
    }

    private void saveMyUsername(String userName) {
        if (TextUtils.isEmpty(userName)) {
            showErrorTip(getString(R.string.edit_username_hint));
            return;
        }
        if (!Pattern.compile("^[a-zA-Z][a-zA-Z0-9_]{3,30}[a-zA-Z0-9]$").matcher(userName).matches()) {
            showErrorTip(getString(R.string.invalid_username_hint));
            return;
        }
        showProgress();
        TelegramManager.getTelegramManager().setMyUserName(this, userName, new TgResultBlock<TgResponse>() {
            @Override
            public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                hideProgress();
                if (obj.ok) {//设置成功
                    finish();
                } else if (obj.errCode == 400) {
                    if ("400_NOT_MODIFY_USERNAME".equals(obj.errString)) {
                        showErrorTip(getString(R.string.unable_modify_username));
                    } else {
                        showErrorTip(getString(R.string.username_already_take));
                    }
                } else {
                    showErrorTip(getString(R.string.request_error) + obj.errString);
                }
            }

            @Override
            public void onTimeout(Map<String, Object> request) {
                hideProgress();
                showErrorTip(getString(R.string.request_error));
            }
        });
    }

    private void saveGroupNickName(String name) {
        if (!StringUtils.isEmpty(name)) {
            showProgress();
            TelegramManager.getTelegramManager().setGroupNickName(this, chatId, name, new TgResultBlock<TgResponse>() {
                @Override
                public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                    hideProgress();
                    if (obj.ok) {//设置成功
                        finish();
                    } else {
                        showErrorTip(getString(R.string.request_error) + obj.errString);
                    }
                }

                @Override
                public void onTimeout(Map<String, Object> request) {
                    hideProgress();
                    showErrorTip(getString(R.string.request_error));
                }
            });
        } else {
            showErrorTip(getString(R.string.fill_my_nickname_in_group));
        }
    }

    private void saveGroupName(String name) {
        if (!StringUtils.isEmpty(name)) {
            showProgress();
            TelegramManager.getTelegramManager().setGroupName(this, chatId, name, new TgResultBlock<TgResponse>() {
                @Override
                public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                    hideProgress();
                    if (obj.ok) {//设置成功
                        finish();
                    } else {
                        showErrorTip(getString(R.string.request_error) + obj.errString);
                    }
                }

                @Override
                public void onTimeout(Map<String, Object> request) {
                    hideProgress();
                    showErrorTip(getString(R.string.request_error));
                }
            });
        } else {
            showErrorTip(getString(R.string.input_group_name));
        }
    }

    private void saveUserNickname(String name) {
//        if (!StringUtils.isEmpty(name)) {
        if (StringUtils.isEmpty(name)) {

            name = "";
        }
        showProgress();
        TelegramManager.getTelegramManager().setContactNickName(this, toBeModifyUser.id, name, new TgResultBlock<TgResponse>() {
            @Override
            public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                hideProgress();
                if (obj.ok) {//设置成功
                    finish();
                } else {
                    showErrorTip(getString(R.string.request_error) + obj.errString);
                }
            }

            @Override
            public void onTimeout(Map<String, Object> request) {
                hideProgress();
                showErrorTip(getString(R.string.request_error));
            }
        });
//        } else {
//            showErrorTip("请填写备注");
//        }
    }

    private void getGroupSensitive_Word() {
        TelegramManager.getTelegramManager().getFilterKeywords(this, chatId, new TgResultBlock<List<String>>() {
            @Override
            public void onResult(Map<String, Object> request, JsonObject response, List<String> obj) {
                hideProgress();
                if (obj != null && obj.size() > 0) {
                    StringBuilder stringBuilder = new StringBuilder();
                    for (int i = 0; i < obj.size(); i++) {
                        stringBuilder.append(obj.get(i));
                        if (i != (obj.size() - 1)) {
                            stringBuilder.append(",");
                        }
                    }
                    binding.valueText.setText(stringBuilder.toString());
                }
            }

            @Override
            public void onTimeout(Map<String, Object> request) {

            }
        });
    }

    private void setGroupSensitive_Word(String content) {
        List<String> keyWords = new ArrayList<>();
        if (!TextUtils.isEmpty(content)) {
            String[] array = content.split(",");
            if (array == null || array.length <= 1) {
                array = content.split("，");
            }
            if (array != null && array.length > 0) {
                keyWords = Arrays.asList(array);
            }
        }
        showProgress();
        TelegramManager.getTelegramManager().setFilterKeywords(this, chatId, keyWords, new TgResultBlock<TgResponse>() {
            @Override
            public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                hideProgress();
                if (obj != null && obj.ok) {
                    showErrorTip(getString(R.string.sensitive_words_success));
                } else {
                    showErrorTip(getString(R.string.request_error));
                }
            }

            @Override
            public void onTimeout(Map<String, Object> request) {
                hideProgress();
                showErrorTip(getString(R.string.request_error));
            }
        });
    }

    public MessageInfo sendingMsg;


    /**
     * 设置群简介
     * @param content
     */
    private void setChatDescription(String content) {
        showProgress();
        TelegramManager.getTelegramManager().setChatDescription(this, chatId, content, new TgResultBlock<TgResponse>() {
            @Override
            public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                hideProgress();
                if (!obj.ok) {
                    showErrorTip(getString(R.string.request_error) + obj.errString);
                } else {
                    Intent intent = getIntent().putExtra("pinned", content);
                    setResult(RESULT_OK,intent);
                    finish();
                }
            }

            @Override
            public void onTimeout(Map<String, Object> request) {
                hideProgress();
                showErrorTip(getString(R.string.request_error));
            }
        });
    }

    private void setGroupPinnedMessage_step1(String content) {
        //第一步，发送文本消息
        //第二步，设置为pinned消息
//        if (!StringUtils.isEmpty(content)) {
            content = String.format("%s%s", Constants.GROUP_NOTICE_PREFIX, content);
            showProgress();
            TelegramManager.getTelegramManager().sendPinTextMessage(this, chatId, content, new TgResultBlock<MessageInfo>() {
                @Override
                public void onResult(Map<String, Object> request, JsonObject response, MessageInfo obj) {
                    if (obj != null) {
                        if (obj.sendState() == TelegramManager.MessageSendState.MessageSendState_Success) {//发送成功
                            setGroupPinnedMessage_step2(obj);
                        } else if (obj.sendState() == TelegramManager.MessageSendState.MessageSendState_Pending) {//等待回调结果
                            hideProgress();
                            sendingMsg = obj;
                        } else {
                            hideProgress();
                            showErrorTip(getString(R.string.request_error));
                        }
                    } else {
                        hideProgress();
                        showErrorTip(getString(R.string.request_error));
                    }
                }

                @Override
                public void onTimeout(Map<String, Object> request) {
                    hideProgress();
                    showErrorTip(getString(R.string.request_error));
                }
            });
//        } else {
//            showErrorTip("请填写群公告");
//        }
    }

    public void setGroupPinnedMessage_step2(MessageInfo msg) {
        TelegramManager.getTelegramManager().setGroupNotice(this, chatId, msg.id, new TgResultBlock<TgResponse>() {
            @Override
            public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                hideProgress();
                if (!obj.ok) {
                    showErrorTip(getString(R.string.request_error) + obj.errString);
                } else {
                    Intent intent = getIntent().putExtra("pinned", msg.content.toString());
                    setResult(RESULT_OK,intent);
                    finish();
                }
            }

            @Override
            public void onTimeout(Map<String, Object> request) {
                hideProgress();
                showErrorTip(getString(R.string.request_error));
            }
        });
    }

    private void click_ok() {
        String valueString = binding.valueText.getText().toString();
        switch (fieldType) {
            case ModifyFieldType_Set_My_Nickname:
                //设置我的昵称
                saveMyNickName(valueString);
                break;
            case ModifyFieldType_Set_My_Username:
                //设置用户名
                saveMyUsername(valueString);
                break;
            case ModifyFieldType_Set_Group_Name:
                //设置群组名称
                saveGroupName(valueString);
                break;
            case ModifyFieldType_Set_User_NickName:
                //设置用户备注
                saveUserNickname(valueString);
                break;
            case ModifyFieldType_Set_GroupSummary:
                //设置群组简介
                setChatDescription(valueString);
                break;
            case ModifyFieldType_Set_GroupNotice:
                //设置群组公告
                setGroupPinnedMessage_step1(valueString);
                break;
            case ModifyFieldType_Set_Sensitive_Word:
                setGroupSensitive_Word(valueString);
                break;
            case ModifyFieldType_Set_My_Signature:
                setMySignature(valueString);
                break;
            case ModifyFieldType_Set_My_Group_Nick_Name:
                saveGroupNickName(valueString);
                break;
            default:
                break;
        }
    }

    private void setMySignature(String content) {
        showProgress();
        TelegramManager.getTelegramManager().setBio(this, content, new TgResultBlock<TgResponse>() {
            @Override
            public void onResult(Map<String, Object> request, JsonObject response, TgResponse obj) {
                hideProgress();
                if (obj != null && obj.ok) {
                    showErrorTip(getString(R.string.signature_success));
                    finish();
                } else {
                    showErrorTip(getString(R.string.request_error));
                }
            }

            @Override
            public void onTimeout(Map<String, Object> request) {
                hideProgress();
                showErrorTip(getString(R.string.request_error));
            }
        });
    }

    @OnClick({R.id.iv_bar_back, R.id.tv_ok_right, R.id.tv_submit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_ok_right:
                if(fieldType == ModifyFieldType.ModifyFieldType_Set_GroupSummary){
                    //删除
                    setChatDescription("");
                }else if(fieldType == ModifyFieldType.ModifyFieldType_Set_GroupNotice){
                    //删除
                    setGroupPinnedMessage_step1("");
                }else{
                    click_ok();
                }
                break;
            case R.id.iv_bar_back:
                finish();
                break;
            case R.id.tv_submit:
                click_ok();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (unbinder != null && unbinder != Unbinder.EMPTY) {
            unbinder.unbind();
        }
    }
}